package com.chen.spring.cloud.miniapp.api.feign.controller;

import com.chen.entity.User;
import com.chen.spring.cloud.miniapp.api.feign.service.OrderService;
import com.chen.spring.cloud.miniapp.api.feign.service.UserService;
import com.chen.util.MapperUtils;
import com.chen.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    private UserService userService;

    @Autowired
    private OrderService orderService;

    @RequestMapping("list")
    public R list(String wx_openid, String is_appointment, String limit, String is_refund, String status){
        String user = userService.getUidByOpenid(wx_openid);
        try {
            User userJson = MapperUtils.json2pojo(user, User.class);
            if (userJson == null){
                return R.error(404,"没有这个用户");
            }
            String result = orderService.getListByLimit(userJson.getU_id(),is_appointment,limit,is_refund,status);
            Map<String,Object> map = MapperUtils.json2map(result);


            return R.ok(map);
        } catch (Exception e){
            e.printStackTrace();
        }
        return R.error(404,"没有订单了");
    }

}
